{# SPDX-FileCopyrightText: © 2019 Siemens AG

   SPDX-License-Identifier: FSFAP
#}
{% extends "include/base.html.twig" %}

{% block content %}
  <h2>{{ "Tag Info"|trans }}</h2>
  {% if tagInvalid == 1 %}
    <h2>{{ "Invalid URL, nonexistant item"|trans }}</h2>
  {% elseif tagInvalid == 2%}
    <h2>{{ "Upload data is unavailable. It needs to be unpacked."|trans }}</h2>
  {% elseif tagsEntries|length > 0 %}
    <table class="table" border="1">
      <tr><th>{{ "File name"|trans }}</th><th>{{ "Tag"|trans }}</th><th></th></tr>
      {% for entry in tagsEntries %}
        <tr>
          <td align="center">{{ entry.ufile_name|e }}</td>
          <td align="center">{{ entry.tag|e }}</td>
          <td align="center">{% if entry.url is not empty %}
            <a href="{{ entry.url|e }}">View</a>
          {% endif %}</td>
        </tr>
      {% endfor %}
    </table>
  {% endif %}

  {% if packageAgentNA == 1 or packageAgentStatus == 1 or packageType is not empty %}
    <h2>{{ "Package Info"|trans }}</h2>
    {% if packageAgentNA == 1 %}
      {{ "No data available. Use Jobs > Agents to schedule a pkgagent scan."|trans }}
    {% elseif packageAgentStatus == 1 %}
      {{ activeScript }}
      <script type="text/javascript">
        function Schedule_Reply()
        {
          if ((Schedule.readyState==4) && (Schedule.status==200))
            document.getElementById("msgdiv").innerHTML = Schedule.responseText;
        }
      </script>

      <form name="formy" method="post">
        <div id="msgdiv">
          {{ "No data available."|trans }}
          <input type="button" name="scheduleAgent" value="Schedule Agent"
          onClick='Schedule_Get("{{ trackback_uri|e }}")' />
        </div>
      </form>
    {% elseif packageType is not empty %}
      {{ packageType|e }}
      <table class="table" border="1" name="pkginfo">
        <tr>
          <th width="5%">{{ "Item"|trans }}</th>
          <th width="20%">{{ "Type"|trans }}</th>
          <th>{{ "Value"|trans }}</th>
        </tr>
        {% for entry in packageEntries %}
          <tr>
            <td align="right">{{ entry.count|e }}</td>
            <td>{{ entry.type|e }}</td>
            <td>{{ entry.value|e }}</td>
          </tr>
        {% endfor %}
        {% for require in packageRequires %}
          <tr>
            <td align="right">{{ require.count|e }}</td>
            <td>{{ require.type|e }}</td>
            <td><a href="{{ require.value|e }}">{{ require.value|e }}</a></td>
          </tr>
        {% endfor %}
      </table>
    {% endif %}
  {% endif %}

  <h2>{{ "File Info"|trans }}</h2>
  <table class="table" border="1">
    <tr>
      <th width="5%">{{ "Item"|trans }}</th>
      <th width="20%">{{ "Meta Data"|trans }}</th>
      <th>{{ "Value"|trans }}</th>
    </tr>
    {% set count = 1 %}
    {% if fileInfo == 1 %}
      {% if displayMimeTypeName is not empty %}
        <tr>
          <td align="right">{{ count }}</td>
          <td>{{ "Unpacked file type"|trans }}</td>
          <td>{{ displayMimeTypeName|e }}</td>
        </tr>
        {% set count = count + 1 %}
      {% endif %}
      {% if getMimeTypeName is not empty %}
        <tr>
          <td align="right">{{ count }}</td>
          <td>{{ "Unpacked file type"|trans }}</td>
          <td>{{ getMimeTypeName|e }}</td>
        </tr>
        {% set count = count + 1 %}
      {% endif %}
      {% if fileUploadOrigin is not empty %}
        <tr>
          <td align="right">{{ count }}</td>
          <td>{{ fileUploadOriginInfo|e }}</td>
          <td>{{ fileUploadOrigin|e }}</td>
        </tr>
        {% set count = count + 1 %}
        <tr>
          <td align="right">{{ count }}</td>
          <td>{{ "Added to repo"|trans }}</td>
          <td>{{ fileUploadDate|e }}</td>
        </tr>
        {% set count = count + 1 %}
      {% endif %}
      <tr>
        <td align="right">{{ count }}</td>
        <td>{{ "Added by"|trans }}</td>
        <td>{{ fileUploadUser|e }}</td>
      </tr>
    {% else %}
      <tr><td colspan="3">{{ "File does not exist in database"|trans }}</td></tr>
    {% endif %}
  </table><br />

  {% if scanossInfo == 1 %}
    <h2>{{ "SCANOSS Matching Info"|trans }}</h2>
    <table class="table" border="1">
      <tr>
        <th width="5%">{{ "Item"|trans }}</th>
        <th>{{ "Value"|trans }}</th>
      </tr>
      <tr><td>{{ "Match type"|trans }}</td> <td>{{ matchType|e }}</td></tr>
      <tr><td>{{ "Line range"|trans }}</td> <td>{{ lineRange|e }}</td></tr>
      <tr><td>{{ "URL"|trans }}</td> <td> <a href={{ url|e }}> {{ url|e }} </a> </td></tr>
      <tr><td>{{ "PURL"|trans }}</td><td>{{ purl|e }}</td></tr>
      <tr><td>{{ "Path"|trans }}</td><td>{{ path|e }}</td></tr>
      </table> 
  {% endif %}


  {% if reusedPackageList is not empty %}
    <h2>{{ "Reused component"|trans }}</h2>
    <table class="table" border="1">
      <thead>
        <tr>
          <th width="5%">{{ "Item"|trans }}</th>
          <th width="25%">{{ "Meta"|trans }}</th>
          <th>{{ "Value"|trans }}</th>
        </tr>
      </thead>
      <tbody>
      {% for reusedPackage in reusedPackageList %}
        <tr>
          <td align="center" rowspan="4">{{ loop.index }}</td>
          <td>{{ "Reused package name"|trans }}</td>
          <td align="right"><a href="{{ reusedPackage.url|e }}">{{ reusedPackage.name|e }}</a></td>
        </tr>
        <tr>
          <td>{{ "Reused package SHA1"|trans }}</td>
          <td align="right">{{ reusedPackage.sha1|e }}</td>
        </tr>
        <tr>
          <td>{{ "Reused package group"|trans }}</td>
          <td align="right">{{ reusedPackage.group|e }}</td>
        </tr>
        <tr>
          <td>{{ "Reused mode"|trans }}</td>
          <td align="right">{{ reusedPackage.mode|e }}</td>
        </tr>
      {% endfor %}
      </tbody>
    </table>
  {% endif %}

  {% if sightingsContent is not empty %}
    <h2>{{ "Sightings"|trans }}</h2>
    {{ sightingsContent }}
  {% endif %}

  {% if repoLocPage == 0 %}
    <h2>{{ "Repository Locator"|trans }}</h2>
    <table class="table" border="1">
      <tr>
        <th>{{ "Attribute"|trans }}</th>
        <th>{{ "Value"|trans }}</th>
      </tr>
      <tr>
        <td align="center">{{ "File Size"|trans }}</td>
        <td align="right">{{ sizeInBytes|e }} {{ sizeInMB|e }}</td>
      </tr>
      <tr>
        <td align="center">{{ "SHA1 Checksum"|trans }}</td>
        <td align="right">{{ fileSha1|e }}</td>
      </tr>
      <tr>
        <td align="center">{{ "MD5 Checksum"|trans }}</td>
        <td align="right">{{ fileMd5|e }}</td>
      </tr>
      <tr>
        <td align="center">{{ "SHA256 Checksum"|trans }}</td>
        <td align="right">{{ fileSha256|e }}</td>
      </tr>
      <tr>
        <td align="center">{{ "Repository ID"|trans }}</td>
        <td align="right">{{ fileSha1|e }}.{{ fileMd5|e }}.{{ fileSize|e }}</td>
      </tr>
      <tr>
        <td align="center">{{ "Pfile ID"|trans }}</td>
        <td align="right">{{ filePfileId|e }}</td>
      </tr>
    </table>
  {% endif %}
{% endblock %}
